/**
 * SwipeRefreshLayout + recyclerView
 */
package com.dm.library.widgets.swiperecyclerview;
/**
 swipeRecyclerView = (SwipeRecyclerView) findViewById(R.id.swipeRecyclerView);

 //set color
 swipeRecyclerView.getSwipeRefreshLayout()
 .setColorSchemeColors(getResources().getColor(R.color.colorPrimary));

 //set layoutManager
 swipeRecyclerView.getRecyclerView().setLayoutManager(new LinearLayoutManager(this));
 //swipeRecyclerView.getRecyclerView().setLayoutManager(new GridLayoutManager(this, 3));
 //swipeRecyclerView.getRecyclerView().setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));

 //禁止下拉刷新
 // swipeRecyclerView.setRefreshEnable(false);

 //禁止加载更多
 //swipeRecyclerView.setLoadMoreEnable(false);

 //设置emptyView
 TextView textView = new TextView(this);
 textView.setText("empty view");
 swipeRecyclerView.setEmptyView(textView);

//设置footerView
//swipeRecyclerView.setFooterView(new SimpleFooterView(this));

//由于SwipeRecyclerView中对GridLayoutManager的SpanSizeLookup做了处理，因此对于使用了
//GridLayoutManager又要使用SpanSizeLookup的情况，可以这样使用！
        swipeRecyclerView.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return 3;
            }
        });

//设置去除footerView 的分割线
       swipeRecyclerView.getRecyclerView().addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
                super.onDraw(c, parent, state);
                Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                paint.setColor(0xFFEECCCC);

                Rect rect = new Rect();
                int left = parent.getPaddingLeft();
                int right = parent.getWidth() - parent.getPaddingRight();
                final int childCount = parent.getChildCount() - 1;
                for (int i = 0; i < childCount; i++) {
                    final View child = parent.getChildAt(i);

                    //获得child的布局信息
                    final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                    final int top = child.getBottom() + params.bottomMargin;
                    final int itemDividerHeight = 1;//px
                    rect.set(left + 50, top, right - 50, top + itemDividerHeight);
                    c.drawRect(rect, paint);
                }
            }
        });

//设置noMore
// swipeRecyclerView.onNoMore("-- end --");

//设置网络处理
//swipeRecyclerView.onNetChange(true);

//设置错误信息
//swipeRecyclerView.onError("error");

data = new ArrayList<>();
        adapter = new RecyclerViewAdapter();
        swipeRecyclerView.setAdapter(adapter);

        swipeRecyclerView.setOnLoadListener(new SwipeRecyclerView.OnLoadListener() {
                @Override
                public void onRefresh() {

                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                data.clear();
                                for (int i = 0; i < pagerSize; i++) {
                                    data.add(String.valueOf(i));
                                }

                                swipeRecyclerView.complete();
                                adapter.notifyDataSetChanged();

                            }
                        }, 1000);

                }

                @Override
                public void onLoadMore() {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                for (int i = 0; i < pagerSize; i++) {
                                    data.add(String.valueOf(i));
                                }

                                if(data.size() > 20){
                                    swipeRecyclerView.onNoMore("-- the end --");
                                }else {
                                    swipeRecyclerView.stopLoadingMore();
                                    adapter.notifyDataSetChanged();
                                }
                            }
                        }, 1000);
                }
        });

        //设置自动下拉刷新，切记要在recyclerView.setOnLoadListener()之后调用
        //因为在没有设置监听接口的情况下，setRefreshing(true),调用不到OnLoadListener
        swipeRecyclerView.setRefreshing(true);

 */